package cn.xfdzx.android.apps.shop.qcshop;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.adapter.ReclerViewAdapter;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.Qc_StoreBean;
import cn.xfdzx.android.apps.shop.bean.Qc_StoreListBean;
import cn.xfdzx.android.apps.shop.contract.Qc_shopContract;
import cn.xfdzx.android.apps.shop.presenter.Qc_shopPresenter;

public class Qc_ShopActivity extends BaseMvpActivity<Qc_shopPresenter> implements Qc_shopContract.View {


    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.view1)
    View view1;
    @BindView(R.id.view2)
    View view2;
    @BindView(R.id.shop_message)
    LinearLayout shopMessage;
    @BindView(R.id.text_list)
    TextView textList;
    @BindView(R.id.recloerview)
    RecyclerView recloerview;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.text_sale)
    TextView textSale;
    @BindView(R.id._mustsale)
    TextView Mustsale;
    @BindView(R.id.button_pay)
    TextView buttonPay;
    @BindView(R.id.iv_logo)
    ImageView ivLogo;
    @BindView(R.id.store_name)
    TextView storeName;
    @BindView(R.id.store_phone)
    TextView storePhone;
    @BindView(R.id.store_people)
    TextView storePeople;
    @BindView(R.id.store_address)
    TextView storeAddress;

    @Override
    public int getLayoutId() {
        return R.layout.activity_qc__shop;
    }

    @Override
    public void initView() {
        refreshLayout.setEnableRefresh(false);
        mPresenter = new Qc_shopPresenter();
        mPresenter.attachView(this);

        Intent intent = getIntent();
        String storeid = intent.getStringExtra("storeid");
        String scantype = intent.getStringExtra("scantype");
        mPresenter.getQcStoreInfor(storeid, 1);
        HashMap<String, Object> map = new HashMap<>();
        map.put("sia", "");
        map.put("page", 1);
        map.put("limit", 10);
        map.put("index_status", 1);
        map.put("is_store", 1);
        map.put("store_id", storeid);
        mPresenter.getQcStoreList(map);

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void forQcStoreInfor(Qc_StoreBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            RoundedCorners roundedCorners = new RoundedCorners(10);

            RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
            Glide.with(this).load(bean.getData().getStore_qualifications_img()).apply(options.transform(new CenterCrop(), roundedCorners)).into(ivLogo);
            storeName.setText(bean.getData().getName());
            storePhone.setText("联系电话：" + bean.getData().getMobile());
            storePeople.setText("联系人：" + bean.getData().getStore_master());
            storeAddress.setText("自提地址：" + bean.getData().getStore_current_address());
        }
    }

    @Override
    public void forQcStoreList(Qc_StoreListBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
            recloerview.setLayoutManager(linearLayoutManager);
            ReclerViewAdapter reclerViewAdapter = new ReclerViewAdapter(this, new ArrayList<>(bean.getData()));
            recloerview.setAdapter(reclerViewAdapter);
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.iv_back, R.id.button_pay})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.button_pay:
                break;
        }
    }
}